﻿using FluentNHibernate.Mapping;

namespace ControleRepresentante.Logic.Models.Maps
{
    public class RepresentanteMap : MapBase<Representante>
    {
        public RepresentanteMap()
        {
            Map(x => x.Nome)
                .Not.Nullable()
                .Unique();
            Map(x => x.Ativo)
                .Not.Nullable();
            HasMany(x => x.Users)
                .Table("SystemUser")
                .Access.PascalCaseField(Prefix.mUnderscore)
                .Cascade.AllDeleteOrphan();
            HasMany(x => x.AttributeHolders)
                .Inverse()
                .Access.PascalCaseField(Prefix.mUnderscore)
                .Cascade.AllDeleteOrphan();
            HasMany(x => x.Attributes)
                .Inverse()
                .Access.PascalCaseField(Prefix.mUnderscore)
                .Cascade.AllDeleteOrphan();
            HasOne(x => x.RepresentanteInfo)
                .Cascade.All();
            Map(x => x.UseJolitex)
                .Not.Nullable();
            Map(x => x.UseTrivium)
                .Not.Nullable();
        }
    }

    public class RepresentanteInfoMap : MapBase<RepresentanteInfo>
    {
        public RepresentanteInfoMap()
        {
            Map(x => x.NomePedido)
                .Not.Nullable();
            Map(x => x.InfoPedido)
                .Nullable();
            References(x => x.VendedorPedidoAttribute)
                .Nullable()
                .Cascade.None();
            HasOne(x => x.Representante);
        }
    }
}
